/*!
 * Ext JS Library 3.3.0
 * Copyright(c) 2006-2010 Ext JS, Inc.
 * licensing@extjs.com
 * http://www.extjs.com/license
 */
Ext.onReady(function() {

    // This is a shared function that simulates a load action on a StatusBar.
    // It is reused by most of the example panels.
    var loadFn = function(btn, statusBar) {
        btn = Ext.getCmp(btn);
        statusBar = Ext.getCmp(statusBar);

        btn.disable();
        statusBar.showBusy();

        (function() {
            statusBar.clearStatus({useDefaults:true});
            btn.enable();
        }).defer(2000);
    };

    Ext.QuickTips.init();
    /*
     * ================  Basic StatusBar example  =======================
     */

    var timeFld = new Ext.form.TimeField({
        id: 'timeFld1',
        fieldLabel: 'Time',
        name: 'time',
        minValue: '8:00am',
        maxValue: '6:00pm',
        qtip: 'Quick Tip 1'
    });
    var chkFld = new Ext.form.Checkbox({
        fieldLabel: 'Check1',
        listeners: {
            focus: function(field) {
                var sb = Ext.getCmp('basic-statusbar');
                sb.setStatus({
                    text: 'Oops!',
                    iconCls: 'x-status-error',
                    clear: true // auto-clear after a set interval
                });
            }
        },
        name: 'check1',
        checked: true
    });

    var formPanel = new Ext.FormPanel({
        //renderTo: 'basic',
        labelWidth: 75, // label settings here cascade unless overridden
        url:'save-form.php',
        frame:true,
        //title: 'Simple Form',
        //bodyStyle:'padding:5px 5px 0',
        //ctCls:'cookieForm',
        //width: 550,
        //defaults: {width: 230},
        defaultType: 'textfield',
        style: 'margin-bottom: 0px',

        //items: [],
        items: [timeFld, chkFld],
        cls: 'cookieForm',

        buttons: [
            {
                text: 'Save',
                handler: function(btn, ev) {
                    layoutFields(formPanel)
                }
            },
            {
                text: 'Cancel'
            }
        ]

    });

    var sbar = new Ext.ux.StatusBar({
        //renderTo: 'basic',
        id: 'basic-statusbar',
        //width: 550,
        // defaults to use when the status is cleared:
        defaultText: 'Default status text',
        //defaultIconCls: 'default-icon',

        // values to set initially:
        text: 'Ready',
        iconCls: 'x-status-valid',

        // any standard Toolbar items:
        items: [
            {
                text: 'Show Warning & Clear',
                handler: function () {
                    var sb = Ext.getCmp('basic-statusbar');
                    sb.setStatus({
                        text: 'Oops!',
                        iconCls: 'x-status-error',
                        clear: true // auto-clear after a set interval
                    });
                }
            },
            {
                text: 'Show Busy',
                handler: function () {
                    var sb = Ext.getCmp('basic-statusbar');
                    // Set the status bar to show that something is processing:
                    sb.showBusy();
                }
            },
            {
                text: 'Clear status',
                handler: function () {
                    var sb = Ext.getCmp('basic-statusbar');
                    // once completed
                    sb.clearStatus();
                }
            },
            '-',
            'Plain Text'
        ]
    });


    new Ext.Panel({
        title: 'Cookie Form',
        renderTo: 'basic',
        //        width: 550,
        //        height: 100,
        width: 600,
        //bodyStyle: 'padding:20px;',
        bbar: sbar,
        items:[formPanel
            //            ,
            //            {
            //            xtype: 'button',
            //            id: 'basic-button',
            //            text: 'Do Loading',
            //            handler: loadFn.createCallback('basic-button', 'basic-statusbar')
            //        }
        ]
    });

    //Ext.get(formPanel.id).setStyle("margin-bottom", "0px");

    Ext.QuickTips.register({
        target: 'timeFld1',
        title: 'My Tooltip',
        text: 'This tooltip was added in code',
        width: 100,
        dismissDelay: 10000 // Hide after 10 seconds hover
    });
    
});